/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IPSecPolicyTable.java
 *
 * Created on 28 févr. 2011, 16:39:41
 */

package gui;

import model.IPSecPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Dudu
 */
public class IPSecPolicyTable extends javax.swing.JPanel {
    private ArrayList<IPSecPolicy> policies;
    private MainFrame mainFrame;
    /** Creates new form IPSecPolicyTable */
    public IPSecPolicyTable(ArrayList<IPSecPolicy> policies,MainFrame mainFrame) {
        this.policies=policies;
        this.mainFrame=mainFrame;
        Iterator itr=policies.iterator();

        initComponents();
                while(itr.hasNext()){
            IPSecPolicy policy=(IPSecPolicy) itr.next();
            DefaultTableModel model=(DefaultTableModel) jTable1.getModel();
            model.addRow(new Object[] {policy.getName(),policy.getSource(),policy.getDestination(),policy.getProtocol(),policy.getDirection(),policy.getAction(),policy.getTunnel_in(),policy.getTunnel_out(),policy.getType(),policy.getTransport_type(),policy.getLevel()});
        }

    }

    public JTable getJTable1() {
        return jTable1;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(903, 551));
        setPreferredSize(new java.awt.Dimension(903, 551));
        setLayout(new java.awt.BorderLayout());

        jScrollPane1.setMinimumSize(new java.awt.Dimension(903, 551));
        jScrollPane1.setPreferredSize(new java.awt.Dimension(903, 551));

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "Source", "Destination", "Protocol", "Direction", "Action", "Tunnel in", "Tunnel out", "Type", "Transport type", "Level"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setCellSelectionEnabled(false);
        jTable1.setColumnSelectionAllowed(false);
        jTable1.setMaximumSize(new java.awt.Dimension(903, 551));
        jTable1.setMinimumSize(new java.awt.Dimension(903, 551));
        jTable1.setPreferredSize(new java.awt.Dimension(903, 551));
        jTable1.setRowSelectionAllowed(true);
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton1.setText("Create new IP Sec Policy");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(296, 296, 296)
                .addComponent(jButton1)
                .addContainerGap(456, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        add(jPanel1, java.awt.BorderLayout.PAGE_END);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        mainFrame.createIPSecPolicy();
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    protected javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    public JTable getjTable1() {
        return jTable1;
    }

}
